<template>
  <app-layout viewName="crm_teamgridexpview" viewTitle="销售渠道表格导航视图" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'degridexpview': true, 'crm-team-grid-exp-view': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
                    <view_gridexpbar 
            :viewState="viewState"  
            :viewparams="viewparams" 
            :context="context" 
            :showBusyIndicator="true" 
            :viewUID="viewUID"
            :newdata="newdata"
            :opendata="opendata"
            name="gridexpbar"  
            ref='gridexpbar' 
            @selectionchange="gridexpbar_selectionchange($event)"  
            @activated="gridexpbar_activated($event)"  
            @load="gridexpbar_load($event)"  
            @closeview="closeView($event)">
        </view_gridexpbar>

      </div>
    </template>
  </app-layout>

</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, GridExpViewBase } from '@/crm-core';
import Crm_teamService from '@/service/crm-team/crm-team-service';

import GridExpViewEngine from '@engine/view/grid-exp-view-engine';


/**
 * 销售渠道表格导航视图基类
 *
 * @export
 * @class Crm_teamGridExpViewBase
 * @extends {GridExpViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class Crm_teamGridExpViewBase extends GridExpViewBase {

    /**
     * 实体服务对象
     *
     * @type {Crm_teamService}
     * @memberof Crm_teamGridExpViewBase
     */
    public appEntityService: Crm_teamService = new Crm_teamService;

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof Crm_teamGridExpViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof Crm_teamGridExpViewBase
	 */
	public viewtag: string = '67484df791fff7f9b19947625b321f8f';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof Crm_teamGridExpViewBase
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof Crm_teamGridExpViewBase
	 */
    protected customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof Crm_teamGridExpViewBase
	 */
    protected customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof Crm_teamGridExpViewBase
     */
    public model: any = {
        srfCaption: 'entities.crm_team.views.gridexpview.caption',
        srfTitle: 'entities.crm_team.views.gridexpview.title',
        srfSubTitle: 'entities.crm_team.views.gridexpview.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof Crm_teamGridExpViewBase
     */
    public containerModel: any = {
        view_gridexpbar: { name: 'gridexpbar', type: 'GRIDEXPBAR' },
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof Crm_teamGridExpViewBase
     */
    public viewState: Subject<ViewState> = new Subject();



    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof Crm_teamGridExpViewBase
     */
    public engine: GridExpViewEngine = new GridExpViewEngine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof Crm_teamGridExpViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            gridexpbar: this.$refs.gridexpbar,
            keyPSDEField: 'crm_team',
            majorPSDEField: 'name',
            isLoadDefault: true,
        });
    }


    /**
     * gridexpbar 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_teamGridExpViewBase
     */
    public gridexpbar_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('gridexpbar', 'selectionchange', $event);
    }


    /**
     * gridexpbar 部件 activated 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_teamGridExpViewBase
     */
    public gridexpbar_activated($event: any, $event2?: any) {
        this.engine.onCtrlEvent('gridexpbar', 'activated', $event);
    }


    /**
     * gridexpbar 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_teamGridExpViewBase
     */
    public gridexpbar_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('gridexpbar', 'load', $event);
    }



    /**
     * 打开新建数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Crm_teamGridExpView
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
    this.$Notice.warning({ title: '错误', desc: '未指定关系视图' });
    }


    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Crm_teamGridExpView
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) {
    this.$Notice.warning({ title: '错误', desc: '未指定关系视图' });
    }




    /**
     * 销毁视图回调
     *
     * @memberof Crm_teamGridExpViewBase
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }

    /**
     * 视图唯一标识
     *
     * @type {string}
     * @memberof Crm_teamGridExpView
     */
    public viewUID: string = 'odoo-crm-crm-team-grid-exp-view';

}
</script>

<style lang='less'>
@import './crm-team-grid-exp-view.less';
</style>